<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>压浆数据平台</title>
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <link rel="stylesheet" href="layui/css/skin.css" media="all">
    <link rel="stylesheet" href="layui/css/table.css" media="all">

    <style>
        #bridgeCodes {
            margin-left: 10%;
            margin-top: 20px;
        }

        #searchs, #searchb {
            margin-top: 20px;

        }

    </style>
</head>
<body>
<div class="bup-header clear">
    <div class="bup-logo"><img src="image/bup-logo.png"/></div>
    <div class="bup-title">
        <h3>压浆数据平台</h3>
    </div>

</div>
<div class="table_div">

    <!-- <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
         <legend>高级应用：制作一个多文件列表</legend>
     </fieldset>
 -->
    <div class="layui-upload">
        <button type="button" class="layui-btn layui-btn-normal" id="testList">选择文件</button>
        <button type="button" class="layui-btn layui-btn-normal" onclick="search()" id="search">设置报表参数</button>
        <div class="layui-upload-list" style="max-width: 1000px;">
            <table class="layui-table">
                <colgroup>
                    <col>
                    <col width="150">
                    <col width="260">
                    <col width="150">
                </colgroup>
                <thead>
                <tr>
                    <th>文件名</th>
                    <th>大小</th>
                    <th>上传进度</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="demoList"></tbody>
            </table>
        </div>
        <button type="button" class="layui-btn" id="testListAction">导出报表</button>

    </div>

</div>
<div id="main" style="width: 450px;height:300px; display: none;"></div>
<div class="layui-form-item" id="uploadParameter" style="display: none">
    <form class="layui-form" id="book" method="post" lay-filter="book">

        <div class="layui-form-item">
            <label class="layui-form-label">施工单位</label>
            <div class="layui-input-inline">
                <input type="text" name="sgdw" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">监理单位</label>
            <div class="layui-input-inline">
                <input type="text" name="jldw" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">工程名称</label>
            <div class="layui-input-inline">
                <input type="text" name="gcmc" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">桩号及部位</label>
            <div class="layui-input-inline">
                <input type="text" name="sgbw" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">合同号</label>
            <div class="layui-input-inline">
                <input type="text" name="htbh" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-inline">
                <input type="text" name="uuid" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">桥梁名称</label>
            <div class="layui-input-inline">
                <input type="text" name="equipmentname" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">终张时间</label>
            <div class="layui-input-inline">
                <input type="text" name="stationed" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管道类型</label>
            <div class="layui-input-inline">
                <input type="text" name="holeinternal" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">梁型</label>
            <div class="layui-input-inline">
                <input type="text" name="lblx" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">跨度(m)</label>
            <div class="layui-input-inline">
                <input type="text" name="holelength" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">压浆料生产厂家</label>
            <div class="layui-input-inline">
                <input type="text" name="snmc" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">压浆料规格</label>
            <div class="layui-input-inline">
                <input type="text" name="yajiangji" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">压浆料批号</label>
            <div class="layui-input-inline">
                <input type="text" name="kongdaoshu" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">压浆设备厂家</label>
            <div class="layui-input-inline">
                <input type="text" name="yajiangfangxiang" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">压浆设备编号</label>
            <div class="layui-input-inline">
                <input type="text" name="yajiangmoshi" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">设备出厂日期</label>
            <div class="layui-input-inline">
                <input type="text" name="zlsj" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
    </form>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="edit">设置上传参数</button>
        <button class="layui-btn layui-btn-sm" lay-event="upload">上传</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="chart">打开</a>
</script>
</body>
<script type="text/javascript" src="layui/layui.js"></script>
<script type="text/javascript" src="layui/jquery.min.js"></script>
<script>
    layui.use(['upload', 'element', 'layer', 'form'], function () {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element;
        //演示多文件列表
        var uploadListIns = upload.render({
            elem: '#testList'
            , elemList: $('#demoList') //列表元素对象
            , url: '/NettyTcpServer/bb/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            , accept: 'file'
            , multiple: false
            , field: 'multipartFile'
            , exts: 'csv'
            , number: 3
            , auto: false
            , bindAction: '#testListAction'
            , choose: function (obj) {
                var that = this;
                var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                //读取本地文件
                obj.preview(function (index, file, result) {
                    var tr = $(['<tr id="upload-' + index + '">'
                        , '<td>' + file.name + '</td>'
                        , '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>'
                        , '<td><div class="layui-progress" lay-filter="progress-demo-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>'
                        , '<td>'
                        , '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
                        , '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
                        , '</td>'
                        , '</tr>'].join(''));

                    //单个重传
                    tr.find('.demo-reload').on('click', function () {
                        obj.upload(index, file);
                    });

                    //删除
                    tr.find('.demo-delete').on('click', function () {
                        delete files[index]; //删除对应的文件
                        tr.remove();
                        uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                    });

                    that.elemList.append(tr);
                    element.render('progress'); //渲染新加的进度条组件
                });
            }
            , done: function (res, index, upload) { //成功的回调
                var that = this;
                if (res.statusCode == 0) { //上传成功
                    var tr = that.elemList.find('tr#upload-' + index)
                        , tds = tr.children();
                    tds.eq(3).html(''); //清空操作
                    delete this.files[index]; //删除文件队列已经上传成功的文件
                    /*  $.ajax({
                          type: "post",
                          url: "/NettyTcpServer/bb/download",
                          data: {
                              filePath: res.responseContent
                          },
                          success: function (obj) {

                          }
                      })*/
                    var url = '/NettyTcpServer/bb/download?filePath=' + res.responseContent;
                    location.href = encodeURI(url);
                    return;
                }
                this.error(index, upload);
            }
            , allDone: function (obj) { //多文件上传完毕后的状态回调
                console.log(obj)
            }
            , error: function (index, upload) { //错误回调
                var that = this;
                var tr = that.elemList.find('tr#upload-' + index)
                    , tds = tr.children();
                tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
            }
            , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
                element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
            }
        });

    });

    function search() {
        layui.use(['layer', 'form', 'laydate'], function () {
            var $ = layui.jquery
                , form = layui.form
                , layer = layui.layer
                , laydate = layui.laydate;
         laydate.index = Date.now();
            layer.open({
                type: 1,
                title: "信息",
                area: ['30%', '50%'],//窗口大小
                btn: ['确定', '取消'],//按钮
                content: $("#uploadParameter"),
                success: function (layero, index) {
                    // 解决按enter键重复弹窗问题
                    $(':focus').blur();
                    // 添加form标识
                    layero.addClass('layui-form');
                    // 将保存按钮改变成提交按钮
                    layero.find('.layui-layer-btn0').attr({
                        'lay-filter': 'book',
                        'lay-submit': ''
                    });
                    $.post("/NettyTcpServer/yj/showParameter", {id: "27"}, function (obj) {
                        $('[name="sgdw"]').val(obj.sgdw),
                            $('[name="jldw"]').val(obj.jldw),
                            $('[name="gcmc"]').val(obj.gcmc),
                            $('[name="sgbw"]').val(obj.sgbw),
                            $('[name="htbh"]').val(obj.htbh),
                            $('[name="uuid"]').val(obj.uuid),
                            $('[name="equipmentname"]').val(obj.equipmentname),
                            $('[name="lblx"]').val(obj.lblx),
                            $('[name="holelength"]').val(obj.holelength),
                            $('[name="snmc"]').val(obj.snmc),
                            $('[name="yajiangji"]').val(obj.yajiangji),
                            $('[name="kongdaoshu"]').val(obj.kongdaoshu),
                            $('[name="yajiangfangxiang"]').val(obj.yajiangfangxiang),
                            $('[name="yajiangmoshi"]').val(obj.yajiangmoshi),
                            $('[name="zlsj"]').val(obj.zlsj),
                            $('[name="stationed"]').val(obj.stationed),
                            $('[name="holeinternal"]').val(obj.holeinternal)

                        form.render('select');
                    });
                    // 刷新渲染(否则开关按钮会不显示)
                    form.render();
                },
                yes: function (index, layero) {
                    // 监听提交按钮
                    form.on('submit(book)', function (data) {
                        $.ajax({
                            type: "post",
                            url: "/NettyTcpServer/yj/updateParameter",
                            data: {
                                id: 27,
                                sgdw: $('[name="sgdw"]').val(),
                                jldw: $('[name="jldw"]').val(),
                                gcmc: $('[name="gcmc"]').val(),
                                sgbw: $('[name="sgbw"]').val(),
                                htbh: $('[name="htbh"]').val(),
                                uuid: $('[name="uuid"]').val(),
                                equipmentname: $('[name="equipmentname"]').val(),
                                lblx: $('[name="lblx"]').val(),
                                holelength: $('[name="holelength"]').val(),
                                snmc: $('[name="snmc"]').val(),
                                yajiangji: $('[name="yajiangji"]').val(),
                                kongdaoshu: $('[name="kongdaoshu"]').val(),
                                yajiangfangxiang: $('[name="yajiangfangxiang"]').val(),
                                yajiangmoshi: $('[name="yajiangmoshi"]').val(),
                                zlsj: $('[name="zlsj"]').val(),
                                stationed: $('[name="stationed"]').val(),
                                holeinternal: $('[name="holeinternal"]').val()

                            },
                            success: function (obj) {
                                layer.msg(obj, {time: 1000}, function () {
                                    layer.close(index);
                                });
                            }
                        })
                        ;
                    })
                }, end: function () {
                    $("#uploadParameter").css('display', 'none');
                }
            })
            //日期时间选择器
            laydate.render({
                elem: '#zlsj'
                , type: 'month'
            });
            laydate.render({
                elem: '#stationed'

            });
        })
    };


    var MaskUtil = (function () {
        var $mask, $maskMsg;
        var defMsg = '正在处理，请稍待。。。';

        function init() {
            if (!$mask) {
                $mask = $("<div></div>")
                    .css({
                        'position': 'absolute'
                        , 'left': '0'
                        , 'top': '0'
                        , 'width': '100%'
                        , 'height': '100%'
                        , 'opacity': '0.3'
                        , 'filter': 'alpha(opacity=30)'
                        , 'display': 'none'
                        , 'background-color': '#ccc'
                    })
                    .appendTo("body");
            }
            if (!$maskMsg) {
                $maskMsg = $("<div></div>")
                    .css({
                        'position': 'absolute'
                        , 'top': '50%'
                        , 'margin-top': '-20px'
                        , 'padding': '5px 20px 5px 20px'
                        , 'width': 'auto'
                        , 'border-width': '1px'
                        , 'border-style': 'solid'
                        , 'display': 'none'
                        , 'background-color': '#ffffff'
                        , 'font-size': '14px'
                    })
                    .appendTo("body");
            }
            $mask.css({width: "100%", height: $(document).height()});
            var scrollTop = $(document.body).scrollTop();
            $maskMsg.css({
                left: ($(document.body).outerWidth(true) - 190) / 2
                , top: (($(window).height() - 45) / 2) + scrollTop
            });
        }

        return {
            mask: function (msg) {
                init();
                $mask.show();
                $maskMsg.html(msg || defMsg).show();
            }
            , unmask: function () {
                $mask.hide();
                $maskMsg.hide();
            }
        }
    }());
</script>
</html>